
SET( ImageCapture_SOURCES ImageCapture.cpp ) 
SET( ImageExposure_SOURCES ImageExposure.cpp ) 
  
message("build type:" ${CMAKE_BUILD_TYPE})      

if(WIN32)
      include_directories ("../Dependencies/opencv340/include") 

      if (CMAKE_CL_64)
            link_directories("../Dependencies/opencv340/x64/lib")
      else ()
            link_directories("../Dependencies/opencv340/x86/lib")
      endif ()

      if (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "DEBUG")
            set(OpenCV_LIBS "opencv_world340d")
      else()
            set(OpenCV_LIBS "opencv_world340")
      endif()
                  
else(UNIX)
      find_package( OpenCV REQUIRED )
      if( OpenCV_FOUND )
            list( APPEND ThirdParty_LIBS ${OpenCV_LIBS} )
            include_directories( ${OpenCV_INCLUDE_DIRS} )
      endif( OpenCV_FOUND )
            include_directories( ${OPENCV_INCLUDE_DIR} ) 
endif(WIN32)

source_group("" FILES ${ImageCapture_SOURCES})
source_group("" FILES ${ImageExposure_SOURCES})

include_directories ("../MoveSenseCamera") 

add_executable (ImageCapture ${ImageCapture_SOURCES})
add_executable (ImageExposure ${ImageExposure_SOURCES})

target_link_libraries(ImageCapture MoveSenseCamera ${OpenCV_LIBS} ${LIBUSB_LIBS})
target_link_libraries(ImageExposure MoveSenseCamera ${OpenCV_LIBS} ${LIBUSB_LIBS})

set_property(TARGET ImageCapture PROPERTY FOLDER "Samples")
set_property(TARGET ImageExposure PROPERTY FOLDER "Samples")

set_target_properties(ImageCapture PROPERTIES
                      RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
set_target_properties(ImageExposure PROPERTIES
                      RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)

if(WIN32)
      if (CMAKE_CL_64)
            add_custom_command(
                  TARGET ImageCapture
                  POST_BUILD
                  COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/Dependencies/opencv340/x64/bin ${CMAKE_CURRENT_BINARY_DIR}
                  DEPENDS ImageCapture
            )
      else ()
            add_custom_command(
                  TARGET ImageCapture
                  POST_BUILD
                  COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/Dependencies/opencv340/x86/bin ${CMAKE_CURRENT_BINARY_DIR}
                  DEPENDS ImageCapture
            )
      endif ()
      
      add_custom_command(
            TARGET ImageCapture
            POST_BUILD
            COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/ConfigFiles ${CMAKE_CURRENT_BINARY_DIR}/ConfigFiles
            DEPENDS ImageCapture
      )
      
      if (CMAKE_CL_64)
            add_custom_command(
                  TARGET ImageExposure
                  POST_BUILD
                  COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/Dependencies/opencv340/x64/bin ${CMAKE_CURRENT_BINARY_DIR}
                  DEPENDS ImageExposure
            )
      else ()
            add_custom_command(
                  TARGET ImageExposure
                  POST_BUILD
                  COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/Dependencies/opencv340/x86/bin ${CMAKE_CURRENT_BINARY_DIR}
                  DEPENDS ImageExposure
            )
      endif ()

      add_custom_command(
            TARGET ImageExposure
            POST_BUILD
            COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/ConfigFiles ${CMAKE_CURRENT_BINARY_DIR}/ConfigFiles
            DEPENDS ImageExposure
      )
else(UNIX)
      add_custom_command(
            TARGET ImageCapture
            POST_BUILD
            COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/ConfigFiles ${PROJECT_BINARY_DIR}/bin/ConfigFiles
            DEPENDS ImageCapture
      )
      
      add_custom_command(
            TARGET ImageExposure
            POST_BUILD
            COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/ConfigFiles ${PROJECT_BINARY_DIR}/bin/ConfigFiles
            DEPENDS ImageExposure
      )
endif(WIN32)

if(WIN32)
install(FILES 
        ${CMAKE_CURRENT_SOURCE_DIR}/ImageCapture.cpp
        DESTINATION ${PROJECT_SOURCE_DIR}/Release/MoveSenseSDK-Windows/Samples/ImageCapture)

install(FILES 
        ${CMAKE_CURRENT_SOURCE_DIR}/ImageExposure.cpp
        DESTINATION ${PROJECT_SOURCE_DIR}/Release/MoveSenseSDK-Windows/Samples/ImageExposure)

else(UNIX)
install(DIRECTORY 
        ${CMAKE_CURRENT_SOURCE_DIR}/../Samples
        DESTINATION ${PROJECT_SOURCE_DIR}/Release/MoveSenseSDK-Linux)

install(DIRECTORY 
        ${CMAKE_CURRENT_SOURCE_DIR}/../Tests
        DESTINATION ${PROJECT_SOURCE_DIR}/Release/MoveSenseSDK-Linux)

endif(WIN32)
